<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      row-key="id"
      :columns="columns"
      :data-source="dataSource"
      :pagination="false"
      :row-selection="rowSelection"
      :custom-row="handleClickRow"
      :row-class-name="tableRowClassName"
      style="height: 300px;overflow-x: hidden; overflow-y: auto;"
    />
    <ProjectModal ref="modalForm" @onSelect="onSelect" />
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ProjectModal from './ProjectModal.vue'
import columns from './indexColumns'

export default {
  name: 'AssistModal',
  components: {
    ProjectModal
  },
  mixins: [JeecgListMixin],
  data() {
    return {
      queryParam: {},
      // 表头
      columns: columns(this),
      url: {
        list: '/sjzxzy/sjZxzyAssistAccount/queryAssistList'
      },
      reportIds: [],
      checkedKeys: [],
      checkedRows: {}
    }
  },
  computed: {
    rowSelection() {
      return {
        type: 'radio',
        onChange: (selectedRowKeys, selectedRows) => {
          this.reportIds = []
          this.checkedKeys = selectedRowKeys
          this.checkedRows = selectedRows
          console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          this.$emit('input', selectedRows[0].assistCode)
          this.$emit('sendAssisCode', selectedRows[0])
        }
      }
    }
  },
  created() {

  },
  mounted() {

  },
  methods: {
    openSearchModel(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.isCheck = false
      this.$refs.modalForm.disableSubmit = false
    },
    handleClickRow(record, index) {
      return {
        on: {
          click: () => {
            console.log(111, record)
            if (this.checkedKeys != [] && this.checkedKeys[0] == record.id) {
              this.openSearchModel(record)
            }
          }
        }
      }
    },
    onSelect(val) {
      const index = this.checkedRows[0].index
      // let assistType = this.dataSource[index].assistCode
      // let assistName = this.dataSource[index].assistName
      const assistCode = val.assCode

      this.dataSource[index].assistItemCode = val.assCode
      this.dataSource[index].assistItemName = val.assName
      this.$emit('onSelectAssist', assistCode)
    },
    updateList() {
      this.loadData(1)
    },
    tableRowClassName(record, index) {
      record.index = index
    }
  }
}
</script>
<style scoped>

</style>
